﻿using B.MES.Customer.Application.IApplication;
using B.MES.Customer.Domain;
using B.MES.Customer.Domain.DTO;
using B.MES.Customer.Infrastructure.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yitter.IdGenerator;

namespace B.MES.Customer.Application.Application
{
    /// <summary>
    /// 物料服务实现层
    /// </summary>
    public class MaterialApplication : BaseApplication<Material>, IMaterialApplication
    {
        private readonly IMaterialRepository _materialRepository;
        public MaterialApplication(IMaterialRepository materialRepository) : base(materialRepository)
        {
            _materialRepository = materialRepository;
        }


        /// <summary>
        /// 带分页的物料查询
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="matCode">物料编号</param>
        /// <param name="matName">物料名称</param>
        /// <param name="matModel">规格型号</param>
        /// <param name="matBrand">品牌</param>
        /// <returns>分页查询结果</returns>
        public PageApiResut<MaterialDTO> GetMaterials(int pageIndex, int pageSize, string? matCode = null, string? matName = null, string? matModel = null, string? matBrand = null)
        {
            return _materialRepository.GetMaterials(pageIndex, pageSize, matCode, matName, matModel, matBrand);
        }

        /// <summary>
        /// 绑定物料属性表的下拉框
        /// </summary>
        /// <returns>返回物料属性表数据</returns>
        public List<Matattribute> GetMatattrShow()
        {
            return _materialRepository.GetMatattrShow();
        }
        /// <summary>
        /// 绑定物料类别表的下拉框
        /// </summary>
        /// <returns>返回物料类别表数据</returns>
        public List<MatTypeinfo> GetMatTypeinfoShow()
        {
            return _materialRepository.GetMatTypeinfoShow();
        }
        /// <summary>
        /// 绑定物料单位表的下拉框
        /// </summary>
        /// <returns>返回物料单位表数据</returns>
        public List<MatUnitInfo> GetMatUnitInfoShow()
        {
            return _materialRepository.GetMatUnitInfoShow();
        }

        /// <summary>
        /// 添加物料表
        /// </summary>
        /// <param name="material">需要添加的物料数据</param>
        /// <returns>受影响的行数</returns>
        public int AddMaterial(Material material)
        {
            return _materialRepository.AddMaterial(material);
        }
    }
}
